/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.scm.hibernate.entities;

import com.scm.hibernate.utilities.HibernateUtil;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import org.hibernate.Query;
import org.hibernate.Session;

/**
 *
 * @author RANGER
 */
@Table(name="spresences")
@Entity
public class Spresence extends AbstractEntity{
    @Id
    @GeneratedValue
    @Column(name = "id")
    private Long id;
    
    @Column(name = "lid")
    private Long lid;
    
    @Transient
    private Lecture lect;
    
    @Column(name = "sid")
    private Long sid;
    
     @Transient
    private Student stu;
    
    
    @Column(name = "status")
    private int status;

    
    public Student getStu() {
        return stu;
    }

    public void setStu(Long sid) {
        this.stu = (Student)new Student().getById(sid);
    }

    
    
    public Lecture getLect() {
        return lect;
    }

    public void setLect(Long lid) {
        this.lect = (Lecture) new  Lecture().getById(lid);
    }
    

    
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Long getLid() {
        return lid;
    }

    public void setLid(Long lid) {
        this.lid = lid;
    }

    public Long getSid() {
        return sid;
    }

    public void setSid(Long sid) {
        this.sid = sid;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

   
    
    
    public static List<Spresence>  getPresenceByStudentId(Long sid){
        List<Spresence> li=null;
        try {
           
            Session session = HibernateUtil.getSessionFactory().openSession();
            //System.out.println("95 : Abstract Entity");
            Query query = session.createQuery("from Spresence where sid="+sid);
            //System.out.println("97 : Abstract Entity");
            li = query.list();
            //System.out.println("99 : Abstract Entity");
            
        } catch (Exception e) {
            e.printStackTrace();
        }
        return li;
    }
}
